<template>
  <el-form ref="form" :model="form" label-width="100px">
    <el-form-item label="课程组名称">
      <el-input v-model="form.name"></el-input>
    </el-form-item>
    <getfile label="选取封面图" :selected="selected1">
      <el-input :value="form.img_URL" disabled></el-input>
    </getfile>
    <getfile label="选取文件" :selected="selected2">
      <el-input :value="form.file_URL" disabled></el-input>
    </getfile>
    <el-form-item label="操作系统">
      <el-select v-model="form.system" placeholder="请选择">
        <el-option label="任何平台" value="0"></el-option>
        <el-option label="windows" value="windows"></el-option>
        <el-option label="mac" value="mac"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="计算机架构">
      <el-select v-model="form.arch" placeholder="请选择">
        <el-option label="任何平台" value="0"></el-option>
        <el-option label="32" value="32"></el-option>
        <el-option label="64" value="64"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item class="text-right">
      <el-button type="primary" @click="onSubmit">立即创建</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { asynccreateFileurl } from "../../../plugins/api.js"; //添加课程组
import getfile from "@/components/admin/getfile.vue";
export default {
  name: "fileurl",
  data() {
    return {
      innerVisible: false,
      form: {
        name: "",
        img_URL: "",
        file_URL: "",
        course_ID: "",
        system: "",
        arch: ""
      },
      rules2: {
        img_URL: [
          { required: true, message: "请选择一个文件", trigger: "blur" }
        ],
        file_URL: [
          { required: true, message: "请选择一个文件", trigger: "blur" }
        ]
      }
    };
  },
  props: ["setdialog", "id"],
  methods: {
    selected1(v) {
      this.form.img_URL = v;
    },
    selected2(v) {
      this.form.file_URL = v;
    },
    namejisuan(course) {
      return `${course.ID}${course.name}${course.paixu}`;
    },
    async onSubmit() {
      try {
        this.form.course_ID = this.id;
        await asynccreateFileurl(this.form);
        this.$store.dispatch("actionFileurl");
        this.$message({
          message: "恭喜你，添加成功",
          type: "success"
        });
        this.form = {
          name: "",
          img_URL: "",
          file_URL: "",
          course_ID: "",
          system: "",
          arch: ""
        };
        await this.setdialog()
      } catch (err) {
        this.$message.error("错了哦，添加失败:" + err);
      }
    }
  },
  components: {
    getfile
  }
};
</script>

<style scoped>
</style>
